import requests

url = 'http://www.baidu.com'
response = requests.get(url)
response.encoding = 'utf-8'

with open('baidu.html', 'w', encoding='utf-8') as f:
    f.write(response.text)

print(response.url)
# 响应url， 有时与请求url不一致
print(response.headers)
# 响应头
print(response.request.headers)
# 查看请求头
print(response.request._cookies)
# 请求携带的cookie
print(response.cookies)
# 响应的cookie （实际上是set-cookie）
print(response.encoding)
print(response.status_code)
# 响应状态码
